<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>待审核订单列表</title>
</head>
<style>
    .table > tbody > tr > td {
        text-align: center;
    }
    .review-class{
        display: flex;
        align-items: flex-start;
        justify-content:space-between;
        margin-bottom: 10px;
    }
    .review-class > select {
        width: 50px;
    }
    .review-class > textarea {
        height: 80px;
    }
</style>
<body>

<div>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 订单管理 <span
            class="c-gray en">&gt;</span> 待审核订单列表 <a class="btn btn-success radius r"
                                                     style="line-height:1.6em;margin-top:3px"
                                                     href="javascript:location.replace(location.href);" title="刷新"><i
            class="Hui-iconfont">&#xe68f;</i></a></nav>
    <form class="page-container">
        <div class="panel panel-default  mt-20">
            <div class="panel-header">时间筛选</div>
            <div class="panel-body">
                <div class="skin-minimal" id="time-selector">
                    <div class="check-box">
                        <input type="radio" name="time" value="0">
                        <label>所有</label>
                    </div>
                    <div class="check-box">
                        <input type="radio" name="time" value="1" checked>
                        <label>当天</label>
                    </div>
                </div>
            </div>
        </div>
        <div class="mt-20">
            <div class="mt-20" style="margin-bottom: 70px">
                <table class="table table-border table-bordered table-bg table-hover table-sort" width="100%">
                    <thead>
                    <tr class="text-c">
                        <th width="25"><input type="checkbox" name="" value=""></th>
                        <th width="80">订单号</th>
                        <th width="80">患者姓名</th>
                        <th width="80">联系电话</th>
                        <th width="100">物品清单</th>
                        <th width="60">下单时间</th>
                        <th width="60">预约时间</th>
                        <th width="80">配送地址</th>
                        <th width="100">医保</th>
                        <th width="100">医保类型</th>
                        <th width="100">付款方式</th>
                        <th width="100">派送人</th>
                        <th width="100">下单人</th>
                        <th width="100">订单状态</th>
                        <th width="50">操作</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </form>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/datatables/dataTables.colReorder.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="lib/common.js"></script>
<script type="text/javascript">

    var start = getTodayStart()
    var end = getTodayEnd()

    for (var i = 1;i<5;i++){
        var t = Date.parse(getTodayStart().replace(/-/g, "/"))
        t = t + i*24*60*60*1000
        $('#time-selector').append("<div class=\"check-box\"><input type=\"radio\" name=\"time\" value="+(parseInt(i)+1)+" ><label>"+dateymd(t)+"</label></div>")
    }



    $('input[name=state],input[name=time]').change(function (e) {

        radioValue = $('input[name=time]:checked').val()
        switch (radioValue) {
            case '1':
                start = getTodayStart()
                end = getTodayEnd()
                break
            case '0':
                start = ""
                end = ""
                break;
            default :
                var t = Date.parse(getTodayStart().replace(/-/g, "/"))
                t = t + (radioValue-1)*24*60*60*1000
                start = dateAll(t)
                var e = Date.parse(getTodayEnd().replace(/-/g, "/"))
                e = e + (radioValue-1)*24*60*60*1000
                end = dateAll(e)
                break;
        }
        console.log(start, end)

        table.destroy()
        table =   $('.table').DataTable({
            serverSide: true,//开启服务器模式
            "processing": true,//加载显示提示
            "ajax": {
                url: "./order/uncomfired/list",
                type: 'GET',
                data: {
                    "searchKey": "",
                    "minDate": start,
                    "maxDate":end,
                    "state":"20"

                }
            },
            "columns": [
                {
                    "data": null,
                    render: function (data, type, row, meta) {
                        return "<input name=\"checkbox\" value=\"" + row.orderId + "\" type=\"checkbox\" value=\"\">";
                    }
                },
                {"data": "orderId"},

                {
                    "data": "receiverName"
                },
                {
                    "data": "receiverPhone"
                },
                {
                    "data": "medicineList",
                    render: function (data, type, row, meta) {
                        var s = ""
                        for (var i = 0;i<data.length;i++){

                            var a ="<span><p>"+data[i].medicineName+data[i].standard +"   数量: "+data[i].num+"</p></span>"
                            s += a;
                        }
                        return s
                    }
                },
                {
                    "data": "createTime",
                    render: function (data, type, row, meta) {
                        return date(data);
                    }
                },
                {
                    "data": "reserveTime",
                    render: function (data, type, row, meta) {
                        return date(data);
                    }
                },
                {
                    "data": "receiverAddress"
                },
                {
                    "data": "insurance"
                },
                {
                    "data": "insuranceType"
                },
                {
                    "data": "paymentType"
                },
                {
                    "data": "deliveryName"
                },
                {
                    "data": "memberName"
                },
                {
                    "data": "status",
                    render: function (data, type, row, meta) {
                        if (data == -1) {
                            return "<span class=\"label label-defant radius td-status\">已取消</span>";
                        } else
                        if (data == 0) {
                            return "<span class=\"label label-defant radius td-status\">待确认</span>";
                        } else if (data == 10) {
                            return "<span class=\"label label-warning radius td-status\">已确认</span>";
                        } else if (data == 20) {
                            return "<span class=\"label label-primary radius td-status\">已配药</span>";
                        } else if (data == 30) {
                            return "<span class=\"label label-secondary radius td-status\">已分配派送员</span>";
                        }else if (data == 35) {
                            return "<span class=\"label label-secondary radius td-status\">配送中</span>";
                        } else if (data == 40) {
                            return "<span class=\"label label-success radius td-status\">已完成</span>";
                        } else if (data == -10) {
                            return "<span class=\"label label-danger radius td-status\">订单取消</span>";
                        } else {
                            return "<span class=\"label label-warning radius td-status\">其它态</span>";
                        }
                    }
                },
                {
                    "data": null,
                    render: function (data, type, row, meta) {
                        // return "123"
                        return '<button class="btn btn-danger radius" type="button" onclick="review(\'' + row.orderId + '\')">审核订单</button>';
                    }
                }
            ],
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": false,//状态保存
            "aoColumnDefs": [
                {"orderable": false, "aTargets": [0]}// 制定列不参与排序
            ],
            language: {
                url: './lib/datatables/Chinese.json'
            },
            colReorder: true
        });
    })
    /*datatables配置*/
    var table =   $('.table').DataTable({
        serverSide: true,//开启服务器模式
        "processing": true,//加载显示提示
        "ajax": {
            url: "./order/uncomfired/list",
            type: 'GET',
            data: {
                "searchKey": "",
                "minDate": start,
                "maxDate": end,
                "state":"20"
            }
        },
        "columns": [
            {
                "data": null,
                render: function (data, type, row, meta) {
                    return "<input name=\"checkbox\" value=\"" + row.orderId + "\" type=\"checkbox\" value=\"\">";
                }
            },
            {"data": "orderId"},

            {
                "data": "receiverName"
            },
            {
                "data": "receiverPhone"
            },
            {
                "data": "medicineList",
                render: function (data, type, row, meta) {
                    var s = ""
                    for (var i = 0;i<data.length;i++){

                        var a ="<span><p>"+data[i].medicineName+data[i].standard +"   数量: "+data[i].num+"</p></span>"
                        s += a;
                    }
                    return s
                }
            },
            {
                "data": "createTime",
                render: function (data, type, row, meta) {
                    return date(data);
                }
            },
            {
                "data": "reserveTime",
                render: function (data, type, row, meta) {
                    return date(data);
                }
            },
            {
                "data": "receiverAddress"
            },
            {
                "data": "insurance"
            },
            {
                "data": "insuranceType"
            },
            {
                "data": "paymentType"
            },
            {
                "data": "deliveryName"
            },
            {
                "data": "memberName"
            },
            {
                "data": "status",
                render: function (data, type, row, meta) {
                    if (data == -1) {
                        return "<span class=\"label label-defant radius td-status\">已取消</span>";
                    } else
                    if (data == 0) {
                        return "<span class=\"label label-defant radius td-status\">待确认</span>";
                    } else if (data == 10) {
                        return "<span class=\"label label-warning radius td-status\">未配药</span>";
                    } else if (data == 20) {
                        return "<span class=\"label label-primary radius td-status\">已配药</span>";
                    } else if (data == 30) {
                        return "<span class=\"label label-secondary radius td-status\">已分配派送员</span>";
                    } else if (data == 40) {
                        return "<span class=\"label label-success radius td-status\">已完成</span>";
                    } else if (data == -10) {
                        return "<span class=\"label label-danger radius td-status\">订单取消</span>";
                    } else {
                        return "<span class=\"label label-warning radius td-status\">其它态</span>";
                    }
                }
            },
            {
                "data": null,
                render: function (data, type, row, meta) {
                    // return "123"
                    return '<button class="btn btn-danger radius" type="button" onclick="review(\'' + row.orderId + '\')">审核订单</button>';

                }
            }
        ],
        "aaSorting": [[1, "desc"]],//默认第几个排序
        "bStateSave": false,//状态保存
        "aoColumnDefs": [
            {"orderable": false, "aTargets": [0]}// 制定列不参与排序
        ],
        language: {
            url: './lib/datatables/Chinese.json'
        },
        colReorder: true
    });



    var ORDERID = ""

    function review(orderId) {
        layer.confirm('<div class="review-class"><span>是否通过审核</span><select id="state"><option value="1">是</option><option value="0">否</option></select></div><div class="review-class"><span>备注</span><textarea placeholder="审核说明，可不填" id="comment"></textarea></div>', {title:"审核订单"}, function (index) {
            var index = layer.load(3);
            var state = $('#state').val()
            var comment = $('#comment').val()
            $.ajax({
                type: 'post',
                url: './order/' + orderId + '/review',
                dataType: 'json',
                data:{
                    comment:comment,
                    state:state
                },
                success: function (data) {
                    layer.close(index);
                    if (data.success != true) {
                        layer.alert(data.message, {title: '错误信息', icon: 2});
                        return;
                    }
                    layer.msg('审核成功!', {icon: 1, time: 1000});
                    // orderCount();
                    refresh();
                },
                error: function (XMLHttpRequest) {
                    layer.close(index);
                    layer.alert('数据处理失败! 错误码:' + XMLHttpRequest.status, {title: '错误信息', icon: 2});
                }
            });
        });
    }


    function msgSuccess(content) {
        layer.msg(content, {icon: 1, time: 3000});
    }
</script>
</body>
</html>